package org.aman.mongo.entity;

import java.util.List;

import javax.mail.Address;

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection="person")
@CompoundIndexes({
    @CompoundIndex(name = "age_idx", def = "{'lastName': 1, 'age': -1}")
})
public class Person1<T extends Address> {

  @Id
  private String id;
  @Indexed(unique = true)
  private Integer ssn;
  private String firstName;
  @Indexed
  private String lastName;
  private Integer age;
  @Transient
  private Integer accountTotal;
  @DBRef
  private List<Account> accounts;
  private T address;

  
  public Person1(Integer ssn) {
    this.ssn = ssn;
  }
  
  @PersistenceConstructor
  public Person1(Integer ssn, String firstName, String lastName, Integer age, T address) {
    this.ssn = ssn;
    this.firstName = firstName;
    this.lastName = lastName;
    this.age = age;
    this.address = address;
  }
}